# 字典, 一系列的健值对
# 创建字典
# 添加键值对
# 修改字典值
# 删除字典键
# 遍历字典 items() keys() values
# 字典、列表嵌套等

# 空字典
# alien_0 = {}
alien_0 = { 'color': 'green', 'points': 5 }

print(alien_0['color'])
print(alien_0['points'])

# 添加键值对
alien_0['x_position'] = 0
alien_0['y_position'] = 25

print(alien_0)

# 修改字典中的值
alien_0['color'] = 'yellow'
alien_0['speed'] = 'medium'

if alien_0['speed'] == 'slow':
    x_increment = 1
elif alien_0['speed'] == 'medium':
    x_increment = 2
else:
    x_increment = 3
alien_0['x_position'] = alien_0['x_position'] + x_increment

print('new x_position:' + str(alien_0['x_position']))

# 删除键值对
del alien_0['points']

print(alien_0)

# 遍历字典, 不关心顺序
user_0 = {
    'username': 'efermi',
    'first': 'enrico',
    'last': 'fermi',
    }

for key, value in user_0.items():
    print('\nKey:' + key)
    print('\nValue:' + value)

favorite_languages = {
    'jen': 'python',
    'sarah': 'c',
    'edward': 'ruby',
    'phil': 'python'
    }

for name in favorite_languages.keys():
    print(name.title())

list_name = list(favorite_languages.keys())
list_value = list(favorite_languages.values())
print(list_name, '\n', list_value, '\n', favorite_languages.keys())

# set, 去重
print(set(favorite_languages.values()))


# 嵌套，字典列表
alien_1 = { 'color': 'green', 'points': 5 }
alien_2 = { 'color': 'yellow', 'points': 10 }
alien_3 = { 'color': 'red', 'points': 15 }
aliens = [alien_0, alien_1, alien_2, alien_3]

print('aliens', aliens)

for alien_number in range(30):
    new_alien = { 'color': 'green', 'points': 5, 'speed': 'slow' }
    aliens.append(new_alien)


pizza: {
    'crust': 'thick',
    'toppings': ['mushrooms', 'extra cheese'],
    }